﻿using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YJ_Code.Entities.Common;
using YJ_Code.Entities.Topic;
using YJ_Code.Enums;
using static YJ_App.Tool.Log.LogDto;

namespace YJ_App.Tool.Log
{
    [ApiDescriptionSettings(ApiGroupEnumsCode.Log, Name = "LogService")]
    public class LogService : IDynamicApiController, ITransient, ILogService
    {
        /// <summary>
        /// sql
        /// </summary>
        private readonly ISqlSugarClient _db;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="db"></param>
        public LogService(ISqlSugarClient db)
        {
            _db = db;
        }

        /// <summary>
        /// 添加日志-封装
        /// </summary>
        /// <returns></returns>
        public async Task AddLog(AddLogInput input)
        {
            try
            {
                await _db.Insertable(new LogRecord
                {
                    Id = Guid.NewGuid().ToString("N"),
                    Content = input.Content,
                    CreateMan = input.UserName,
                    CreateTime = DateTime.Now,
                    TopicId = input.TopicId,
                    Type = input.Type,
                    IsDelete = false,

                }).ExecuteCommandAsync();
            }
            catch (Exception)
            {

                throw Oops.Bah($"日志操作异常【{input.Content}】");
            }
        }
    }
}
